<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\controller\property\system\sms;

use think\App;
use app\controller\property\Base;
use app\common\repositories\system\sms\SystemSmsLogRepository;


class SmsLog extends Base
{
    protected $repository;

    public function __construct(App $app, SystemSmsLogRepository $repository)
    {
        parent::__construct($app);

        $this->repository = $repository;
    }

    /**
     * 短信发送日志
     * @return string|\think\response\Json
     * @throws \Exception
     *
     * @author Amos
     * 2024-01-22 17:13
     */
    public function list()
    {
        if ($this->request->isAjax()) {
            $param = $this->request->param([
                'mobile' => '',
                'keywords' => '',
                'is_verify' => ''
            ]);
            [$page, $limit] = $this->getPage();
            $data = $this->repository->getpropertyList($param, $page, $limit, $this->request->propertyId);
            return json()->data(['code' => 0, 'data' => $data['list'], 'count' => $data['count']]);
        }
        return $this->fetch('system/sms/log/list', [
            'delAuth' => property_auth('propertySmsLogDel'),
        ]);
    }

    /**
     * 删除短信发送日志
     * @return string|\think\response\Json|\think\response\View
     *
     * @author Amos
     * 2024-01-22 17:12
     */
    public function del()
    {
        $ids = (array)$this->request->param('ids');
        try {
            $data = $this->repository->batchDelete($ids, $this->request->propertyUId);
            if ($data) {
                return $this->success('删除成功');
            } else {
                return $this->error('删除失败');
            }
        } catch (\Exception $e) {
            exception_log('删除短信发送日志失败', $e);
            return $this->error('网络错误');
        }
    }

}